---
title: Profiling
description: Learn how to profile Turbopack
---

import { ThemedImageFigure } from '#/components/image/themed-image-figure';

## On macOS

### Install [`cargo-instruments`]

```bash title="Terminal"
cargo install cargo-instruments
```

Make sure you have all the [prerequisites](https://github.com/cmyr/cargo-instruments#pre-requisites) for running cargo-instruments.

### Run the profiler

By default, `turbopack-cli dev` will keep watching for changes to your application and never exit until you manually interrupt it. However, [`cargo-instruments`] waits for your program to exit before building and opening the trace file. For this purpose, we've added a `profile` feature to `turbopack-cli` which exits the program if no updates are detected within a given time frame and there are no pending tasks.

To profile `turbopack-cli`, run the following command:

```bash title="Terminal"
cargo instruments -t time --bin turbopack-cli --release --features profile [-- [...args]]
```

You can also run [other templates](https://github.com/cmyr/cargo-instruments#templates) than the time profiler.

Once the program exits, the profiler will open the trace file in Instruments. Refer to the [learning resources](https://github.com/cmyr/cargo-instruments#resources) to learn how to use Instruments.

<ThemedImageFigure
  borderRadius={true}
  dark={{
    source: '/images/docs/pack/instruments-dark.png',
    height: 662,
    width: 968,
  }}
  light={{
    source: '/images/docs/pack/instruments-light.png',
    height: 706,
    width: 1012,
  }}
  captionSpacing={24}
  caption="An example trace from the time profiler."
/>

## Linux

### Memory usage

```bash title="Terminal"
# Install `heaptrack` and `heaptrack_gui`
sudo apt install heaptrack heaptrack_gui

# Compile with debug info but without the alternative allocator:
CARGO_PROFILE_RELEASE_DEBUG=1 cargo build --bin turbopack-cli --release --no-default-features --features native-tls

# Run the binary with heaptrack (it will be much slower than usual)
heaptrack target/release/turbopack-cli [...]

# Stop it anytime

# Open the GUI and open the heaptrack.turbopack-cli.XXX.gz file
heaptrack_gui
```

## On other platforms

We currently don't have a guide for profiling Turbopack on other platforms.

[`cargo-instruments`]: https://github.com/cmyr/cargo-instruments
